package com.example.csetpp.controller;

import com.example.csetpp.pojo.dto.richText.ChangeRichTextDTO;
import com.example.csetpp.pojo.dto.richText.DeleteRichText;
import com.example.csetpp.pojo.dto.richText.SaveRichTextDTO;
import com.example.csetpp.service.RichTextService;
import com.example.csetpp.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "富文本功能相关")
@RequestMapping("/user/richText")
public class RichTextController {

    @Autowired
    private RichTextService richTextService;

    @Operation(summary = "富文本存储")
    @PostMapping("/save")
    public Result saveRichText(@RequestBody SaveRichTextDTO saveRichTextDTO) {
        return richTextService.saveRichText(saveRichTextDTO);
    }

    @Operation(summary = "更新富文本")
    @PostMapping("/update")
    public Result changeRichText(@RequestBody ChangeRichTextDTO changeRichTextDTO) {
        return richTextService.changeRichText(changeRichTextDTO);
    }

    @Operation(summary = "删除富文本")
    @PostMapping("/delete")
    public Result deleteRichText(@RequestBody DeleteRichText deleteRichText) {
        return richTextService.deleteRichText(deleteRichText);
    }

    @Operation(summary = "获取所有富文本")
    @PostMapping("/get-all")
    public Result getAll() {
        return richTextService.getAll();
    }


    @Operation(summary = "返回存储的富文本")
    @PostMapping("/getText")
    public Result getTextByTitle(@RequestParam String phone,
                                 @RequestParam String password,
                                 @RequestParam String title) {
        return richTextService.getTextByTitle(phone, password, title);
    }
}
